Skip to content

Linux Basic Operation

File Operation

Rename

  • Rename a.txt into b.txt
shell
mv a.txt b.txt
  • 得到交互提示(在存在同名文件的情况下)得到提示,防止误操作
shell
mv -i a.txt b.txt
  • Copy-Delete Operation
shell
cp a.txt b.txt
rm a.txt
  • rename command
    • rename命令的使用是rename oldfile newfile matchfile
shell
rename a.txt b.txt a.txt

rename命令的优点是它可以用来批量重命名文件和目录,支持正则表达式。 例如我们想要批量重命名“txt”文件为“log”文件,可以使用以下命令:

shell
rename .txt .log *.txt

rename命令支持多种参数,下面介绍一些常用参数:

  1. -v:显示重命名的详细信息
  2. -n:显示模拟执行的结果,但不实际执行
  3. -f:强制执行,忽略存在的文件
  4. -i:忽略大小写
  5. -h:显示帮助信息。

Vim Basic

CommandDescription中文描述
aInsert text after the cursor在光标后插入文本
iInsert text before the cursor在光标前插入文本
:wq, ZZSave changes and exit保存更改并退出
:q, :q!Exit without saving (:q! forces exit)不保存退出(:q! 强制退出)
:wSave changes but continue editing保存更改但继续编辑
Ctrl+FMove forward one page向前翻页
/textSearch forward for text向后查找文本
?textSearch backward for text向前查找文本
:!bashTemporarily exit to execute a bash command; use exit to return临时退出执行bash命令;使用exit返回编辑
xDelete the character at the cursor删除光标处的字符
ddDelete the current line删除当前行
uUndo the last modification撤销上一次修改
mv file fileFolderMove file to fileFolder将文件移动到文件夹中
cp file fileFolderCopy file to fileFolder将文件复制到文件夹中
rm -rf file, rm -f fileRemove a directory (-rf) or file (-f)删除文件夹(-rf)或文件(-f
lsList files in the directory查看文件目录
ls -aList all files including hidden ones查看所有文件,包括隐藏文件
llList all files with detailed info including permissions列出所有文件,包括权限等详细信息